/*
 * @Author: Jinsc
 * @Date: 2022-11-13 13:47:15
 * @LastEditors: Jinsc
 * @LastEditTime: 2022-12-04 09:55:34
 * @FilePath: \视频\lvgl_weather_main\components\lvgl_porting\lv_task.c
 * @Description: 
 * Copyright (c) 2022 by jinsc123654@gmail.com All Rights Reserved. 
 */
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "./driver/gpio.h"
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "lv_demos.h"
#include "lv_task.h"
#include "lvgl_app/lvgl_app.h"
#define SPIFFS_PATH "/spiffs"
/*用定时器给LVGL提供时钟*/
static void lv_tick_task(void *arg)
{
	(void)arg;
	lv_tick_inc(10);
}

void lv_task(void *arg)
{
    lv_init();
    lv_port_disp_init();
    lv_mount_cus_font();

    // gpio_config_t pGPIOConfig = 
    // {
    //     .intr_type      = GPIO_INTR_DISABLE,
    //     .mode           = GPIO_MODE_INPUT,
    //     .pin_bit_mask   = GPIO_SEL_4,
    //     .pull_down_en   = GPIO_PULLDOWN_DISABLE,
    //     .pull_up_en     = GPIO_PULLUP_ENABLE
    // };
    // gpio_config(&pGPIOConfig);
    // pGPIOConfig.pin_bit_mask = GPIO_SEL_5;
    // gpio_config(&pGPIOConfig);
    // pGPIOConfig.pin_bit_mask = GPIO_SEL_16;
    // gpio_config(&pGPIOConfig);

    // lv_port_indev_init();
    // lv_group_t *group = lv_group_create();
    // lv_indev_set_group(indev_keypad, group);

    /*  esp_register_freertos_tick_hook(lv_tick_task);
    Create and start a periodic timer interrupt to call lv_tick_inc 
    */
    const esp_timer_create_args_t periodic_timer_args = {
        .callback = &lv_tick_task,
        .name = "periodic_gui"};
    esp_timer_handle_t periodic_timer;
    ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
    ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, 10 * 1000));

    // LV_IMG_DECLARE(img_bulb_gif);
    // lv_obj_t * img;

    // img = lv_gif_create(lv_scr_act());
    // lv_gif_set_src(img, &img_bulb_gif);
    // lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

    // img = lv_gif_create(lv_scr_act());
    /* Assuming a File system is attached to letter 'A'
     * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */
    //lv_gif_set_src(img, "A:lvgl/examples/libs/gif/bulb.gif");
    // lv_gif_set_src(img, SPIFFS_PATH"/bulb.gif");
    // lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
    
    lv_weather_main();
    while(1)
    {
        lv_task_handler();
        vTaskDelay(pdMS_TO_TICKS(10));
    }
}